package com.ybkj.daijia.api.weixin.entity;

import com.ybkj.daijia.api.weixin.WxMsgType;
import com.ybkj.daijia.api.weixin.WxXmlUtil;
import org.dom4j.DocumentException;
import org.dom4j.Element;

public abstract class WxBaseRespEntity extends WxBaseEntity {

    protected Integer funcFlag;

    protected String toUserName;

    protected String fromUserName;

    protected Long createTime;

    protected String msgType;

    public Integer getFuncFlag() {
        return funcFlag;
    }

    public void setFuncFlag(Integer funcFlag) {
        this.funcFlag = funcFlag;
    }

    public String getToUserName() {
        return toUserName;
    }

    public void setToUserName(String toUserName) {
        this.toUserName = toUserName;
    }

    public String getFromUserName() {
        return fromUserName;
    }

    public void setFromUserName(String fromUserName) {
        this.fromUserName = fromUserName;
    }

    public Long getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Long createTime) {
        this.createTime = createTime;
    }

    public String getMsgType() {
        return msgType;
    }

    public void setMsgType(String msgType) {
        this.msgType = msgType;
    }

    public Element toXML() throws DocumentException {

        WxMsgType type = WxMsgType.valueOf(getMsgType());

        switch (type) {
            case image:
                return WxXmlUtil.getRespImage((WxRespImageEntity) this);
            case music:
                return WxXmlUtil
                    .getRespMusic((WxRespMusicEntity) this, ((WxRespMusicEntity) this).getThumb());
            case news:
                return WxXmlUtil.getRespPicDesc((WxRespPicDescEntity) this);
            case text:
                return WxXmlUtil.getRespTextXML((WxRespTextEntity) this);
            case video:
                return WxXmlUtil.getRespVideo((WxRespVideoEntity) this);
            case voice:
                return WxXmlUtil.getRespVoice((WxRespVoiceEntity) this);
            default:
                break;
        }

        return null;
    }

}